package java_0629;

import java.util.Scanner;

public class ThreadDemo16 {
    static class Counter{
        volatile public int flag = 0;
    }

    public static void main(String[] args) {
        Counter counter = new Counter();
        Thread t1 = new Thread(){
            @Override
            public void run() {
                while(counter.flag == 0){

                }
                System.out.println("线程执行结束了");
            }
        };
        t1.start();
        Thread t2 = new Thread(){
            @Override
            public void run() {
                Scanner scanner = new Scanner(System.in);
                System.out.print("请输入一个数：");
                int n = scanner.nextInt();
                counter.flag = n;
            }
        };

        t2.start();
    }
}
